package com.example.day16_mp;

import android.Manifest;
import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity {

    private TabLayout tab;
    private ViewPager vp;

    List<Fragment> list = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    MyFragAdapter myFragAdapter;
    private TextView name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        requestPermissions(new String[]{
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.READ_CONTACTS,
                Manifest.permission.WRITE_CONTACTS,
                Manifest.permission.READ_SMS,
                Manifest.permission.CALL_PHONE,
                Manifest.permission.ACCESS_NETWORK_STATE,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.WRITE_CALL_LOG,
                Manifest.permission.READ_CALL_LOG
        }, 100);
        initView();

        list.add(new BlankFragment());
        list.add(new BlankFragment2());
        list.add(new BlankFragment3());

        titles.add("在线");
        titles.add("本地");
        titles.add("收藏");

        myFragAdapter = new MyFragAdapter(getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, list, titles);
        vp.setAdapter(myFragAdapter);
        tab.setupWithViewPager(vp);
        if(getIntent().getExtras()!=null){//判断是直接启动的，还是点击通知拉起的
            String type = (String) getIntent().getExtras().get("type");
            if ("1".equals(type)) {
                name.setText(MusicUtils.getInstance().getName());
            }
        }

    }

    private void initView() {
        tab = (TabLayout) findViewById(R.id.tab);
        vp = (ViewPager) findViewById(R.id.vp);
        name = (TextView) findViewById(R.id.name);
    }
}